﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using System.Threading;
using System.IO;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO.Ports;
using weiqijiance;
using ZedGraph;
using CCWin;
using Newtonsoft.Json;

namespace weiqijiance
{
    public partial class yiqijianding : CCSkinMain
    {
        public mainform m_mainform;
        public bool bldpy;
        public bool bssxysj;
        public bool bxjxysj;
        public DateTime tqsj;
        public DateTime tztqsj;

        public yiqijianding()
        {
            InitializeComponent();
            bldpy = false;
            timer1.Enabled = false;
            textBox3.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }

        private void skinBut_ksjc_Click(object sender, EventArgs e)
        {
            txtstartxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            bldpy = false;
            bssxysj = false;
            bxjxysj = false;
            m_mainform.objfqy.SendDeviceCmd(29);
            timer1.Enabled = true;
            this.Invoke(new Action(() => { this.txttishi.Text = "通检查气中，请将"+CBBND.Text+"气体通入到仪器"; }));
        }
        public bool mhcgoodz=true;
        public bool mcogoodz = true;
        public bool mnogoodz = true;
        public bool mcogoodz2 = true;
        public bool mogoodz2 = true;//总判定

        private void skinButton1_Click(object sender, EventArgs e)
        {
            txtendxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            this.Invoke(new Action(() => { this.txttishi.Text = "检测完成"; }));
            timer1.Enabled = false;
            //m_mainform.objfqy.SendDeviceCmd(2);
            //Thread.Sleep(500);
            m_mainform.objfqy.SendDeviceCmd(24);
            //
            #region 获取合格CO
            if (CO_bzz.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入CO标准值");
            }
            else
            {
                if (float.Parse(CO_bzz.Text) < 10)
                {
                    text_hgco.Text = string.Format("±3%/±0.02");
                }
                else if (float.Parse(CO_bzz.Text) > 10.01 && float.Parse(CO_bzz.Text) < 14.00)
                {
                    text_hgco.Text = string.Format("±5%/-");

                }
            }
            #endregion

            #region 获取hc合格
            if (HC_bzz.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入HC标准值");
            }
            else
            {
                if (float.Parse(HC_bzz.Text) < 2000)
                {
                    text_hghc.Text = string.Format("±3%/±4");
                }
                else if (float.Parse(HC_bzz.Text) > 2001 && float.Parse(HC_bzz.Text) < 5000)
                {
                    text_hghc.Text = string.Format("±5/-");

                }
                else if (float.Parse(HC_bzz.Text) > 5001 && float.Parse(HC_bzz.Text) < 9999)
                {
                    text_hghc.Text = string.Format("±10/-");
                }
            }
            #endregion

            #region 获取NO合格
            if (NO_bzz.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入NO标准值");
            }
            else
            {
                if (float.Parse(NO_bzz.Text) < 4000)
                {
                    text_hgno.Text = string.Format("±4%/25");
                }
                else if (float.Parse(NO_bzz.Text) > 4001 && float.Parse(NO_bzz.Text) < 5000)
                {
                    text_hgno.Text = string.Format("±8%/-");

                }
            }
            #endregion

            #region 获取合格CO2
            if (CO2_bzz.Text.Trim() == string.Empty)
            {
                //      MessageBox.Show("请输入CO2标准值");
            }
            else
            {
                if (float.Parse(CO2_bzz.Text) < 16)
                {
                    text_hgco2.Text = string.Format("±3%/±0.02");
                }
                else if (float.Parse(CO2_bzz.Text) > 16.01 && float.Parse(CO2_bzz.Text) < 18.00)
                {
                    text_hgco2.Text = string.Format("±5%/-");

                }
            }
            #endregion

            compareHC(HC_bzz.Text, HC_cyz.Text, "低标");
            compareCO(CO_bzz.Text, CO_cyz.Text, "低标");
            compareCO2(CO2_bzz.Text, CO2_cyz.Text, "低标");
            compareNO(NO_bzz.Text, NO_cyz.Text, "低标");
            //compareO2(O2_bzz.Text, O2_cyz.Text, "低标");
            if (mhcgoodz && mcogoodz && mnogoodz && mcogoodz2 && mogoodz2)
            {
                text_dpjg.Text = "合格";
            }
            else
            {
                text_dpjg.Text = "不合格";
            }

            //
            iniclass objini = new iniclass();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");

            objini.Writue("废气仪检定", "HC标准值", HC_bzz.Text);
            objini.Writue("废气仪检定", "HC检定值", HC_cyz.Text);
            objini.Writue("废气仪检定", "CO标准值", CO_bzz.Text);
            objini.Writue("废气仪检定", "CO检定值", CO_cyz.Text);
            objini.Writue("废气仪检定", "NO标准值", NO_bzz.Text);
            objini.Writue("废气仪检定", "NO检定值", NO_cyz.Text);
            objini.Writue("废气仪检定", "CO2标准值", CO2_bzz.Text);
            objini.Writue("废气仪检定", "CO2检定值", CO2_cyz.Text);
            objini.Writue("废气仪检定", "C3H8", C3H8_BZZ.Text);
            objini.Writue("废气仪检定", "PEF", txtpef.Text);
            objini.Writue("废气仪检定", "气体类型", C3H8_BZZ.Text);
            objini.Writue("废气仪检定", "判定", text_dpjg.Text);
            objini.Writue("废气仪检定", "检定时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            
            ///记录检定数据      
            string sjieguo = string.Format(@"HC标准值{0};检定值{1};CO标准值{2};检定值{3};NO标准值{4};检定值{5};",
                                                    HC_bzz.Text,
                                                    HC_cyz.Text,
                                                     CO_bzz.Text,
                                                    CO_cyz.Text,
                                                   NO_bzz.Text,
                                                    NO_cyz.Text);
            string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                         "废气仪",
                                         sjieguo,
                                         DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                         m_mainform.lineCode);
            m_mainform.objbassLW.objdb.InsertDB(ssqlex);

        }
        private void compareHC(string hcbz, string hcsc, string dibiaohuogaobiao)//bz---a,sc---b
        {
            #region compareHC
            float hca = float.Parse(hcsc) - float.Parse(hcbz);
            float hcb = 100 * (float.Parse(hcsc) - float.Parse(hcbz)) / float.Parse(hcbz);
            float value = Math.Abs(hca);
            float value1 = Math.Abs(hcb);
            bool hcgood = true;
            bool hcgood1 = true;
            bool hcgoodz = true;

            if (float.Parse(hcbz) <= 2000)
            {
                if (value > 4 && value1 > 3)
                {
                    hcgood = false;
                    hcgood1 = false;
                }

            }
            else if (float.Parse(hcbz) >= 2001 && float.Parse(hcbz) <= 5000)
            {
                if (value1 > 5)
                {
                    hcgood = false;
                }

            }
            else if (float.Parse(hcbz) >= 5001 && float.Parse(hcbz) <= 9999)
            {
                if (value1 > 10)
                {
                    hcgood = false;
                }

            }

            if (!hcgood && !hcgood1)
            {
                hcgoodz = false;

            }
            else
            {

            }
            mhcgoodz = hcgoodz;
            #endregion
        }

        private void compareCO(string cobz, string cosc, string dibiaohuogaobiao)
        {
            #region compareCO
            double coa = Math.Round((float.Parse(cobz) - float.Parse(cosc)), 3);
            float cob = 100 * (float.Parse(cobz) - float.Parse(cosc)) / float.Parse(cobz);
            double value = Math.Abs(coa);
            float value1 = Math.Abs(cob);
            bool cogood = true;
            bool cogood1 = true;
            bool cogoodz = true;
            if (Math.Round((float.Parse(cobz))) <= 10.00)
            {
                if (value > 0.02 && value1 > 3)
                {
                    cogood = false;
                    cogood1 = false;
                }

            }
            else if (float.Parse(cobz) >= 10.01 && float.Parse(cobz) <= 14.00)
            {
                if (value1 > 5)
                {
                    cogood = false;
                }

            }

            if (!cogood && !cogood1)
            {
                cogoodz = false;

            }
            else
            {

            }
            mcogoodz = cogoodz;
            #endregion

        }

        private void compareCO2(string cobz2, string cosc2, string dibiaohuogaobiao)
        {
            #region compareCO2
            double coa2 = Math.Round((float.Parse(cobz2) - float.Parse(cosc2)), 3);
            float cob2 = 100 * (float.Parse(cobz2) - float.Parse(cosc2)) / float.Parse(cobz2);
            double value = Math.Abs(coa2);
            float value1 = Math.Abs(cob2);
            bool cogood2 = true;
            bool cogood3 = true;
            bool cogoodz2 = true;
            if (Math.Round((float.Parse(cobz2))) <= 16.00)
            {
                if (value > 0.30 && value1 > 3)
                {
                    cogood2 = false;
                    cogood3 = false;
                }

            }
            else if (float.Parse(cobz2) >= 16.10 && float.Parse(cobz2) <= 18.00)
            {
                if (value1 > 5)
                {
                    cogood2 = false;
                }

            }

            if (!cogood2 && !cogood3)
            {
                cogoodz2 = false;

            }
            else
            {

            }
            mcogoodz2 = cogoodz2;
            #endregion

        }

        private void compareNO(string nobz, string nosc, string dibiaohuogaobiao)
        {
            #region compareNO
            float noa = float.Parse(nosc) - float.Parse(nobz);
            float nob = 100 * (float.Parse(nosc) - float.Parse(nobz)) / float.Parse(nobz);
            float value = Math.Abs(noa);
            float value1 = Math.Abs(nob);
            bool nogood = true;
            bool nogood1 = true;
            bool nogoodz = true;
            if (float.Parse(nobz) <= 4000)
            {
                if (value > 25 && value1 > 4)
                {
                    nogood = false;
                    nogood1 = false;
                }

            }
            else if (float.Parse(nobz) >= 4001 && float.Parse(nobz) <= 5000)
            {
                if (value1 > 8)
                {
                    nogood = false;
                }

            }
            if (!nogood && !nogood1)
            {
                nogoodz = false;

            }
            else
            {

            }
            mnogoodz = nogoodz;
            #endregion

        }

        private void compareO2(string o2bz, string o2sc, string dibiaohuogaobiao)
        {
            #region 02
            float oa2 = float.Parse(o2sc) - float.Parse(o2bz);
            float ob2 = 100 * (float.Parse(o2sc) - float.Parse(o2bz)) / float.Parse(o2bz);
            float value = Math.Abs(oa2);
            float value1 = Math.Abs(ob2);
            bool ogood2 = true;
            bool ogood1 = true;
            bool ogoodz2 = true;

            if (value > 0.1 && value1 > 5)
            {
                ogood2 = false;
                ogood1 = false;
            }

            if (!ogood2 && !ogood1)
            {
                ogoodz2 = false;

            }
            else
            {

            }
            mogoodz2 = ogoodz2;

            #endregion
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            m_mainform.objfqy.SendDeviceCmd(3);
            #region
            if (!bldpy)
            {
                Thread.Sleep(300);

                HC_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_iHc);
                CO_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_fCo.ToString("0.00"));
                NO_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_iNo);
                CO2_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_fCo2);
                O2_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_fO2);
                //txtpef.Text = string.Format(@"{0}", m_mainform.objfqy.m_pef);

                #region 获取合格CO
                if (CO_bzz.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入CO标准值");
                }
                else
                {
                    if (float.Parse(CO_bzz.Text) < 10)
                    {
                        text_hgco.Text = string.Format("±3%/±0.02");
                    }
                    else if (float.Parse(CO_bzz.Text) > 10.01 && float.Parse(CO_bzz.Text) < 14.00)
                    {
                        text_hgco.Text = string.Format("±5%/-");

                    }
                }
                #endregion

                #region 获取hc合格
                if (HC_bzz.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入HC标准值");
                }
                else
                {
                    if (float.Parse(HC_bzz.Text) < 2000)
                    {
                        text_hghc.Text = string.Format("±3%/±4");
                    }
                    else if (float.Parse(HC_bzz.Text) > 2001 && float.Parse(HC_bzz.Text) < 5000)
                    {
                        text_hghc.Text = string.Format("±5/-");

                    }
                    else if (float.Parse(HC_bzz.Text) > 5001 && float.Parse(HC_bzz.Text) < 9999)
                    {
                        text_hghc.Text = string.Format("±10/-");
                    }
                }
                #endregion

                #region 获取NO合格
                if (NO_bzz.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入NO标准值");
                }
                else
                {
                    if (float.Parse(NO_bzz.Text) < 4000)
                    {
                        text_hgno.Text = string.Format("±4%/25");
                    }
                    else if (float.Parse(NO_bzz.Text) > 4001 && float.Parse(NO_bzz.Text) < 5000)
                    {
                        text_hgno.Text = string.Format("±8%/-");

                    }
                }
                #endregion

                #region 获取合格CO2
                if (CO2_bzz.Text.Trim() == string.Empty)
                {
                    //      MessageBox.Show("请输入CO2标准值");
                }
                else
                {
                    if (float.Parse(CO2_bzz.Text) < 16)
                    {
                        text_hgco2.Text = string.Format("±3%/±0.02");
                    }
                    else if (float.Parse(CO2_bzz.Text) > 16.01 && float.Parse(CO2_bzz.Text) < 18.00)
                    {
                        text_hgco2.Text = string.Format("±5%/-");

                    }
                }
                #endregion

                compareHC(HC_bzz.Text, HC_cyz.Text, "低标");
                compareCO(CO_bzz.Text, CO_cyz.Text, "低标");
                compareCO2(CO2_bzz.Text, CO2_cyz.Text, "低标");
                compareNO(NO_bzz.Text, NO_cyz.Text, "低标");
                //compareO2(O2_bzz.Text, O2_cyz.Text, "低标");
                if (mhcgoodz && mcogoodz && mnogoodz && mcogoodz2 && mogoodz2)
                {
                    text_dpjg.Text = "合格";
                }
                else
                {
                    text_dpjg.Text = "不合格";
                }

            }
            #endregion
            shuaxin();//计算绝对值、相对值
            if (bldpy)
                getldpy();         
            if (bt90start)
                gett90();
            if (bt10start)
                gett10();
      

        }

        Thread t2;
        private void skinButton4_Click(object sender, EventArgs e)
        {

            txtstartxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //m_mainform.SendDeviceCmdGas(0x66, 0x95);//泄漏检查
            //if (comboBox1.Text.Contains("废气仪"))
            {
                m_mainform.objfqy.SendDeviceCmd(10);
                Thread.Sleep(1000);
                t2 = new Thread(thread2);
                t2.Start();
            }
            //else
            //{
            //    m_mainform.objbtg.SendDeviceCmd(15);
            //    Thread.Sleep(1000);
            //    t2 = new Thread(thread2cy);
            //    t2.Start();
            //}
        }
        public string endtimexl = "";

        private void thread2cy()
        {
            DateTime date = DateTime.Now;

            sxianshineirong = "泄露检测中";
            xianshixinxi();
            Thread.Sleep(20000);
            //m_mainform.m_fxlbs = true;
            m_mainform.objfqy.m_fxlbs = true;
            while (true)
            {

                //m_mainform.SendDeviceCmdGas(0x61, 0x9A);//获取状态
                m_mainform.objbtg.SendDeviceCmd(6);
                Thread.Sleep(1000);
                //if (!m_mainform.objfqy.m_fxlbs)
                //{
                //    sxianshineirong = "泄露检测完成";
                //    break;
                //}
                //else
                {
                    sxianshineirong = "泄露检测中";
                }
                xianshixinxi();
                if ((DateTime.Now - date).TotalMilliseconds > 1000 * 40)
                {
                    break;
                }
            }
            //int ixl = m_mainform.objfqy.m_fxl;
            //if (ixl == 1)
            //{
            //    sxianshineirong = "泄露不合格";
            //}
            //else
            {
                sxianshineirong = "泄露合格";
            }
            xianshixinxi();
            endtimexl = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            xianshixielouend();
            ///记录检定数据      
            string sjieguo = string.Format(@"泄露检测：{0}", sxianshineirong);
            string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                         "不透光",
                                         sjieguo,
                                         DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                         m_mainform.lineCode);
            m_mainform.objbassLW.objdb.InsertDB(ssqlex);
        }
        private void thread2()
        {
            DateTime date = DateTime.Now;

            sxianshineirong = "泄露检测中";
            xianshixinxi();
            Thread.Sleep(20000);
            //m_mainform.m_fxlbs = true;
            m_mainform.objfqy.m_fxlbs = true;
            while (true)
            {

                //m_mainform.SendDeviceCmdGas(0x61, 0x9A);//获取状态
                m_mainform.objfqy.SendDeviceCmd(6);
                Thread.Sleep(1000);
                if (!m_mainform.objfqy.m_fxlbs)
                {
                    sxianshineirong = "泄露检测完成";
                    break;
                }
                else
                {
                    sxianshineirong = "泄露检测中";
                }
                xianshixinxi();
                if ((DateTime.Now - date).TotalMilliseconds > 1000 * 40)
                {
                    break;
                }
            }
            int ixl = m_mainform.objfqy.m_fxl;
            if (ixl == 1)
            {
                sxianshineirong = "泄露不合格";
            }
            else
            {
                sxianshineirong = "泄露合格";
            }
            xianshixinxi();
            endtimexl = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            xianshixielouend();
            ///记录检定数据      
            string sjieguo = string.Format(@"泄露检测：{0}", sxianshineirong);
            string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                         "废气仪",
                                         sjieguo,
                                         DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                         m_mainform.lineCode);
            m_mainform.objbassLW.objdb.InsertDB(ssqlex);
        }
        string sxianshineirong = "";
        private delegate void FlushClient();//代理
        private void xianshixinxi()
        {
            if (this.xl_fq.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xl_fq.Text = string.Format(@"{0}", sxianshineirong);
            }
        }

        private void xianshixielouend()
        {
            if (this.txtendxl.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixielouend);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtendxl.Text = string.Format(@"{0}", endtimexl);
            }
        }
        private void yiqijianding_Load(object sender, EventArgs e)
        {

            iniclass objini = new iniclass();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
            txtpef.Text = objini.ReadValue("废气仪检定", "PEF");

            iniCZY("CZY");
            txtstartxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            txtendxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            textBox1.Text = m_mainform.stationCode;
            textBox2.Text = m_mainform.lineCode;
            textBox3.Text = DateTime.Now.ToString("yyyy-MM-dd");
            skinCom_czy.Text = m_mainform.sczyxx;
            getqiti("汽油", CBBND.Text);
            x = this.Width;
            y = this.Height;
            setTag(this);
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }

        public void iniCZY(string dataname)
        {

            string ssqlex = "";
            //ssqlex = string.Format(@"select * from {0}", dataname);
            ssqlex = string.Format(@"select * from Employee where EP_TYPE ='引车员'");
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                skinCom_czy.Items.Add(dt.Rows[i]["EP_NAME"].ToString().Trim());
                if (i == 0)
                    skinCom_czy.Text = dt.Rows[0]["EP_NAME"].ToString().Trim();
            }
        }
        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        private void skinButton5_Click(object sender, EventArgs e)
        {
            model.尾气自检.xljc objxljc = new model.尾气自检.xljc();
            objxljc.dtCheckDate = txtstartxl.Text;
            objxljc.dtBeginTime = txtstartxl.Text;
            objxljc.dtEndTime = txtendxl.Text;
            objxljc.nJudegeResult = xl_fq.Text.Contains("合格") ? "1" : "2";
            objxljc.szRemark = "";
            objxljc.syq = "1";
            objxljc.jcry = skinCom_czy.Text;
            MessageBox.Show(m_mainform.objbass.uploadzj(objxljc));
        }

        private void skinButton6_Click(object sender, EventArgs e)
        {
            model.尾气自检.yliangcheng objxljc = new model.尾气自检.yliangcheng();
            objxljc.dtCheckDate = txtstartxl.Text;//	氧量程检查日期（yyyy-MM-dd HH:mm:ss）
            objxljc.dtBeginTime = txtstartxl.Text;//	氧量程检查开始时间（yyyy-MM-dd HH:mm:ss）
            objxljc.dtEndTime = txtendxl.Text;//	氧量程检查结束时间（yyyy-MM-dd HH:mm:ss）
            objxljc.CheckVal = ylc_cyz.Text;//	测量值 (%)
            objxljc.StdVal = ylc_bzz.Text;//	标准值 (%)
            objxljc.DivVal = ylc_jdc.Text;//	绝对差 (%)
            objxljc.nJudgeResult = "1";//	最终判定结果（0未完成，1合格，2不合格）
            MessageBox.Show(m_mainform.objbass.uploadzj(objxljc));//5.6.4	废气分析仪氧量程检查
        }

        private void skinButton8_Click(object sender, EventArgs e)
        {
            model.尾气自检.zjgcsj objgcsjbzq = new model.尾气自检.zjgcsj();
            if (CBBND.Text.Length < 1)
            {
                MessageBox.Show("请选择气体浓度");
                return;
            }
            float fpefxx = 0;
            if (!float.TryParse(txtpef.Text, out fpefxx))
            {
                MessageBox.Show("请输入正确的PEF");
                return;
            }
            if (!(skinComboBox1.Text.Length>1))
            {
                MessageBox.Show("请选择检验类型");
                return;
            }
            
            objgcsjbzq.dtCheckDate = txtstartxl.Text;
            objgcsjbzq.dtBeginTime=txtstartxl.Text;
            objgcsjbzq.dtEndTime=txtendxl.Text;
            string szCheckType="3";
            if (CBBND.Text.Contains("中低浓度"))
            {
                szCheckType = "3";
            }
            else if (CBBND.Text.Contains("低浓度"))
            {
                szCheckType = "3";
            }
            else if (CBBND.Text.Contains("中高浓度"))
            {
                szCheckType = "5";
            }
            else if (CBBND.Text.Contains("高浓度"))
            {
                szCheckType = "5";
            }
            else if (CBBND.Text.Contains("零"))
            {
                szCheckType = "4";
            }
            objgcsjbzq.szCheckType = szCheckType;//1-加载滑行 2-附加损失 3-单点检查（低标 气）4-单点检查（零气）5-单点检查（高标气） 6-五点检查
            if (szCheckType != "5")
            {
                objgcsjbzq.icount = 3;
                int ihcgc = 0;
                int.TryParse(HC_cyz.Text, out ihcgc);
                float icogc = 0;
                float.TryParse(CO_cyz.Text, out icogc);
                int inogc = 0;
                int.TryParse(NO_cyz.Text, out inogc);
                float ico2gc = 0;
                float.TryParse(CO2_cyz.Text, out ico2gc);

                objgcsjbzq.stringHC.Add(0);
                objgcsjbzq.stringCO.Add(0);
                objgcsjbzq.stringNO.Add(0);
                objgcsjbzq.stringCO2.Add(0);

                objgcsjbzq.stringHC.Add(ihcgc * 0.4f);
                objgcsjbzq.stringCO.Add(icogc * 0.4f);
                objgcsjbzq.stringNO.Add(inogc * 0.4f);
                objgcsjbzq.stringCO2.Add(ico2gc * 0.4f);

                objgcsjbzq.stringHC.Add(ihcgc);
                objgcsjbzq.stringCO.Add(icogc);
                objgcsjbzq.stringNO.Add(inogc);
                objgcsjbzq.stringCO2.Add(ico2gc);
            }
            else
            {
                objgcsjbzq.icount = 5;
                int ihcgc = 0;
                int.TryParse(HC_cyz.Text, out ihcgc);
                float icogc = 0;
                float.TryParse(CO_cyz.Text, out icogc);
                int inogc = 0;
                int.TryParse(NO_cyz.Text, out inogc);
                float ico2gc = 0;
                float.TryParse(CO2_cyz.Text, out ico2gc);

                objgcsjbzq.stringHC.Add(0);
                objgcsjbzq.stringCO.Add(0);
                objgcsjbzq.stringNO.Add(0);
                objgcsjbzq.stringCO2.Add(0);

                objgcsjbzq.stringHC.Add(ihcgc * 0.4f);
                objgcsjbzq.stringCO.Add(icogc * 0.4f);
                objgcsjbzq.stringNO.Add(inogc * 0.4f);
                objgcsjbzq.stringCO2.Add(ico2gc * 0.4f);

                objgcsjbzq.stringHC.Add(ihcgc * 0.7f);
                objgcsjbzq.stringCO.Add(icogc * 0.7f);
                objgcsjbzq.stringNO.Add(inogc * 0.7f);
                objgcsjbzq.stringCO2.Add(ico2gc * 0.7f);

                objgcsjbzq.stringHC.Add(ihcgc * 0.9f);
                objgcsjbzq.stringCO.Add(icogc * 0.9f);
                objgcsjbzq.stringNO.Add(inogc * 0.9f);
                objgcsjbzq.stringCO2.Add(ico2gc * 0.9f);

                objgcsjbzq.stringHC.Add(ihcgc);
                objgcsjbzq.stringCO.Add(icogc);
                objgcsjbzq.stringNO.Add(inogc);
                objgcsjbzq.stringCO2.Add(ico2gc);
            }
            string smexshow = m_mainform.objbass.upzjgcsj(objgcsjbzq);
            if (smexshow.Length > 1)
            {
                MessageBox.Show(smexshow);
            }
            model.尾气自检.fqyddjc objxljc = new model.尾气自检.fqyddjc();

            objxljc.dtCheckDate = txtstartxl.Text;
            objxljc.dtBeginTime = txtstartxl.Text;
            objxljc.dtEndTime = txtendxl.Text;
            objxljc.CheckDate = txtstartxl.Text;
            objxljc.CheckType = "2";
            objxljc.PEF = txtpef.Text;
            objxljc.Checkkind = skinComboBox1.Text;

            objxljc.CheckValHC = HC_cyz.Text;
            objxljc.StdValHC = HC_bzz.Text;
            objxljc.RateValHC = txthcxdc.Text;//相对值
            objxljc.DivValHC = txthcjdc.Text;//绝对值
            objxljc.CheckJudgeHC = "1";
            objxljc.T10ValHC = "0";
            objxljc.T10StdHC = "0";
            objxljc.T10JudgeHC = "0";
            objxljc.T90ValHC = "0";
            objxljc.T90StdHC = "0";
            objxljc.T90JudgeHC = "0";
            objxljc.JudgeResultHC = "1";

            objxljc.CheckValCO = CO_cyz.Text;
            objxljc.StdValCO = CO_bzz.Text;
            objxljc.RateValCO = txtcoxdc.Text;
            objxljc.DivValCO = txtcojdc.Text;
            objxljc.CheckJudgeCO = "1";
            objxljc.T10ValCO = "0";
            objxljc.T10StdCO = "0";
            objxljc.T10JudgeCO = "0";
            objxljc.T90ValCO = "0";
            objxljc.T90StdCO = "0";
            objxljc.T90JudgeCO = "0";
            objxljc.JudgeResultCO = "1";

            objxljc.CheckValNO = NO_cyz.Text;
            objxljc.StdValNO = NO_bzz.Text;
            objxljc.RateValNO = txtnoxdc.Text;
            objxljc.DivValNO = txtnojdc.Text;
            objxljc.CheckJudgeNO = "1";
            objxljc.T10ValNO = "0";
            objxljc.T10StdNO = "0";
            objxljc.T10JudgeNO = "0";
            objxljc.T90ValNO = "0";
            objxljc.T90StdNO = "0";
            objxljc.T90JudgeNO = "0";
            objxljc.JudgeResultNO = "1";

            objxljc.CheckValCO2 = CO2_cyz.Text;
            objxljc.StdValCO2 = CO2_bzz.Text;
            objxljc.RateValCO2 = txtco2xdc.Text;
            objxljc.DivValCO2 = txtco2jdc.Text;
            objxljc.CheckJudgeCO2 = "1";
            objxljc.T10ValCO2 = "0";
            objxljc.T10StdCO2 = "0";
            objxljc.T10JudgeCO2 = "0";
            objxljc.T90ValCO2 = "0";
            objxljc.T90StdCO2 = "0";
            objxljc.T90JudgeCO2 = "0";
            objxljc.JudgeResultCO2 = "1";

            objxljc.CheckTypeex = CBBND.Text;
            objxljc.C3H8 = C3H8_BZZ.Text;
            objxljc.StdValO2 = O2_bzz.Text;
            objxljc.CheckValO2 = O2_cyz.Text;
            objxljc.Checker = skinCom_czy.Text;


            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + "\\检测自检\\稳态工况设备自检信息.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);

            iniclass objiniex = new iniclass();
            string pathex = "";
            pathex = System.Windows.Forms.Application.StartupPath + "\\检测自检\\双怠速设备自检信息.ini";
            string path1ex = string.Format(@"{0}", pathex);
            objiniex.Ini(path1ex);

            if (CBBND.Text.Contains("中低浓度"))
            {
                objini.Writue("记录", "ML_HC", HC_cyz.Text);
                objini.Writue("记录", "ML_HC_Error", txthcxdc.Text);
                objini.Writue("记录", "ML_HC_Judge", "1");
                objini.Writue("记录", "ML_CO", CO_cyz.Text);
                objini.Writue("记录", "ML_CO_Error", txtcoxdc.Text);
                objini.Writue("记录", "ML_CO_Judge", "1");
                objini.Writue("记录", "ML_NO", NO_cyz.Text);
                objini.Writue("记录", "ML_NO_Error", txtnoxdc.Text);
                objini.Writue("记录", "ML_NO_Judge", "1");

                objiniex.Writue("记录", "ML_HC", HC_cyz.Text);
                objiniex.Writue("记录", "ML_HC_Error", txthcxdc.Text);
                objiniex.Writue("记录", "ML_HC_Judge", "1");
                objiniex.Writue("记录", "ML_CO", CO_cyz.Text);
                objiniex.Writue("记录", "ML_CO_Error", txtcoxdc.Text);
                objiniex.Writue("记录", "ML_CO_Judge", "1");
                objiniex.Writue("记录", "ML_NO", NO_cyz.Text);
                objiniex.Writue("记录", "ML_NO_Error", txtnoxdc.Text);
                objiniex.Writue("记录", "ML_NO_Judge", "1");
            }
            else if (CBBND.Text.Contains("低浓度"))
            {
                objini.Writue("记录", "Low_HC", HC_cyz.Text);
                objini.Writue("记录", "Low_HC_Error", txthcxdc.Text);
                objini.Writue("记录", "Low_HC_Judge", "1");
                objini.Writue("记录", "Low_CO", CO_cyz.Text);
                objini.Writue("记录", "Low_CO_Error", txtcoxdc.Text);
                objini.Writue("记录", "Low_CO_Judge", "1");
                objini.Writue("记录", "Low_NO", NO_cyz.Text);
                objini.Writue("记录", "Low_NO_Error", txtnoxdc.Text);
                objini.Writue("记录", "Low_NO_Judge", "1");

                objiniex.Writue("记录", "Low_HC", HC_cyz.Text);
                objiniex.Writue("记录", "Low_HC_Error", txthcxdc.Text);
                objiniex.Writue("记录", "Low_HC_Judge", "1");
                objiniex.Writue("记录", "Low_CO", CO_cyz.Text);
                objiniex.Writue("记录", "Low_CO_Error", txtcoxdc.Text);
                objiniex.Writue("记录", "Low_CO_Judge", "1");
                objiniex.Writue("记录", "Low_NO", NO_cyz.Text);
                objiniex.Writue("记录", "Low_NO_Error", txtnoxdc.Text);
                objiniex.Writue("记录", "Low_NO_Judge", "1");
            }
            else if (CBBND.Text.Contains("中高浓度"))
            {

                objini.Writue("记录", "MH_HC", HC_cyz.Text);
                objini.Writue("记录", "MH_HC_Error", txthcxdc.Text);
                objini.Writue("记录", "MH_HC_Judge", "1");
                objini.Writue("记录", "MH_CO", CO_cyz.Text);
                objini.Writue("记录", "MH_CO_Error", txtcoxdc.Text);
                objini.Writue("记录", "MH_CO_Judge", "1");
                objini.Writue("记录", "MH_NO", NO_cyz.Text);
                objini.Writue("记录", "MH_NO_Error", txtnoxdc.Text);
                objini.Writue("记录", "MH_NO_Judge", "1");

                objiniex.Writue("记录", "MH_HC", HC_cyz.Text);
                objiniex.Writue("记录", "MH_HC_Error", txthcxdc.Text);
                objiniex.Writue("记录", "MH_HC_Judge", "1");
                objiniex.Writue("记录", "MH_CO", CO_cyz.Text);
                objiniex.Writue("记录", "MH_CO_Error", txtcoxdc.Text);
                objiniex.Writue("记录", "MH_CO_Judge", "1");
                objiniex.Writue("记录", "MH_NO", NO_cyz.Text);
                objiniex.Writue("记录", "MH_NO_Error", txtnoxdc.Text);
                objiniex.Writue("记录", "MH_NO_Judge", "1");
            }
            else if (CBBND.Text.Contains("高浓度"))
            {
                objini.Writue("记录", "High_HC", HC_cyz.Text);
                objini.Writue("记录", "High_HC_Error", txthcxdc.Text);
                objini.Writue("记录", "High_HC_Judge", "1");
                objini.Writue("记录", "High_CO", CO_cyz.Text);
                objini.Writue("记录", "High_CO_Error", txtcoxdc.Text);
                objini.Writue("记录", "High_CO_Judge", "1");
                objini.Writue("记录", "High_NO", NO_cyz.Text);
                objini.Writue("记录", "High_NO_Error", txtnoxdc.Text);
                objini.Writue("记录", "High_NO_Judge", "1");

                objiniex.Writue("记录", "High_HC", HC_cyz.Text);
                objiniex.Writue("记录", "High_HC_Error", txthcxdc.Text);
                objiniex.Writue("记录", "High_HC_Judge", "1");
                objiniex.Writue("记录", "High_CO", CO_cyz.Text);
                objiniex.Writue("记录", "High_CO_Error", txtcoxdc.Text);
                objiniex.Writue("记录", "High_CO_Judge", "1");
                objiniex.Writue("记录", "High_NO", NO_cyz.Text);
                objiniex.Writue("记录", "High_NO_Error", txtnoxdc.Text);
                objiniex.Writue("记录", "High_NO_Judge", "1");
            }
            else if (CBBND.Text.Contains("零"))
            {
                objini.Writue("记录", "Zero_HC", HC_cyz.Text);
                objini.Writue("记录", "Zero_HC_Error", txthcxdc.Text);
                objini.Writue("记录", "Zero_HC_Judge", "1");
                objini.Writue("记录", "Zero_CO", CO_cyz.Text);
                objini.Writue("记录", "Zero_CO_Error", txtcoxdc.Text);
                objini.Writue("记录", "Zero_CO_Judge", "1");
                objini.Writue("记录", "Zero_NO", NO_cyz.Text);
                objini.Writue("记录", "Zero_NO_Error", txtnoxdc.Text);
                objini.Writue("记录", "Zero_NO_Judge", "1");

                objiniex.Writue("记录", "Zero_HC", HC_cyz.Text);
                objiniex.Writue("记录", "Zero_HC_Error", txthcxdc.Text);
                objiniex.Writue("记录", "Zero_HC_Judge", "1");
                objiniex.Writue("记录", "Zero_CO", CO_cyz.Text);
                objiniex.Writue("记录", "Zero_CO_Error", txtcoxdc.Text);
                objiniex.Writue("记录", "Zero_CO_Judge", "1");
                objiniex.Writue("记录", "Zero_NO", NO_cyz.Text);
                objiniex.Writue("记录", "Zero_NO_Error", txtnoxdc.Text);
                objiniex.Writue("记录", "Zero_NO_Judge", "1");
            }
            else
            {
                objini.Writue("记录", "Low_HC", HC_cyz.Text);
                objini.Writue("记录", "Low_HC_Error", txthcxdc.Text);
                objini.Writue("记录", "Low_HC_Judge", "1");
                objini.Writue("记录", "Low_CO", CO_cyz.Text);
                objini.Writue("记录", "Low_CO_Error", txtcoxdc.Text);
                objini.Writue("记录", "Low_CO_Judge", "1");
                objini.Writue("记录", "Low_NO", NO_cyz.Text);
                objini.Writue("记录", "Low_NO_Error", txtnoxdc.Text);
                objini.Writue("记录", "Low_NO_Judge", "1");

                objiniex.Writue("记录", "Low_HC", HC_cyz.Text);
                objiniex.Writue("记录", "Low_HC_Error", txthcxdc.Text);
                objiniex.Writue("记录", "Low_HC_Judge", "1");
                objiniex.Writue("记录", "Low_CO", CO_cyz.Text);
                objiniex.Writue("记录", "Low_CO_Error", txtcoxdc.Text);
                objiniex.Writue("记录", "Low_CO_Judge", "1");
                objiniex.Writue("记录", "Low_NO", NO_cyz.Text);
                objiniex.Writue("记录", "Low_NO_Error", txtnoxdc.Text);
                objiniex.Writue("记录", "Low_NO_Judge", "1");
            }
            string sjieguo = string.Format(@"{0}单点检查信息：{1}", CBBND.Text, JsonConvert.SerializeObject(objxljc));
            string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                         CBBND.Text + "单点检查信息",
                                         sjieguo,
                                         DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                         m_mainform.lineCode);
            m_mainform.objbassLW.objdb.InsertDB(ssqlex);
            MessageBox.Show(m_mainform.objbass.uploadzj(objxljc));
        }

        private void skinButton7_Click_1(object sender, EventArgs e)
        {
            m_mainform.objbass.JCZT("1");
        }

        private void skinButton10_Click(object sender, EventArgs e)
        {
            m_mainform.objbass.JCZT("2");
        }

        private void C3H8_BZZ_TextChanged(object sender, EventArgs e)
        {
            float fc3h8 = 0, fhc = 0, fpef = 0;
            float.TryParse(C3H8_BZZ.Text, out fc3h8);
            float.TryParse(HC_bzz.Text, out fhc);
            float.TryParse(txtpef.Text, out fpef);
            if (fpef > 0 && fc3h8 > 0)
            {
                HC_bzz.Text = Math.Round(fc3h8 * fpef).ToString();
            }
        }


        private void yiqijianding_Resize(object sender, EventArgs e)
        {
           
        }

        Thread t3;
        public void thread3()
        {
            Thread.Sleep(60000);
            this.Invoke(new Action(() => { this.txttishi.Text = "零点飘移检定开始，请等待结束"; }));
            this.Invoke(new Action(() => { timer1.Enabled = true; }));
        }
        DateTime dtimetldpy = DateTime.Now;
        private void skinButton3_Click(object sender, EventArgs e)
        {
            txtstartxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            this.Invoke(new Action(() => { this.txttishi.Text = "零点飘移检定准备开始，请等待1分钟"; }));
            dtimetldpy = DateTime.Now;
            C3H8_BZZ.Visible = false;
            txtpef.Visible = false;
            CBBND.Visible = false;
            HC_bzz.Text = "0";
            CO_bzz.Text = "0";
            NO_bzz.Text = "0";
            CO2_bzz.Text = "0";
            O2_bzz.Text = "0";
            HC_cyz.Text = "0";
            CO_cyz.Text = "0";
            NO_cyz.Text = "0";
            CO2_cyz.Text = "0";
            O2_cyz.Text = "0";
            text_hghc.Text = "±4/-";
            text_hgco.Text = "±0.02/-";
            text_hgno.Text = "±0.3/-";
            text_hgco2.Text = "±25/-";
            text_hgo2.Text = "±0.1/±5%";
            bldpy = true;
            m_mainform.objfqy.SendDeviceCmd(25);//抽气

            t3 = new Thread(thread3);
            t3.Start();
        }

        private void skinButton9_Click(object sender, EventArgs e)
        {
            txtendxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            timer1.Enabled = false;
            m_mainform.objfqy.SendDeviceCmd(24);
            this.Invoke(new Action(() => { this.txttishi.Text = "零点飘移检定结束"; }));
        }

        private void skinButton11_Click(object sender, EventArgs e)
        {
            bldpy = false;
            //m_mainform.objfqy.SendDeviceCmd(1);//启动废气仪
            //Thread.Sleep(500);
            m_mainform.objfqy.SendDeviceCmd(29);//通入检查气

            tqsj = DateTime.Now;
            timer1.Enabled = true;
           
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            bxjxysj = true;
            tztqsj = DateTime.Now;
            m_mainform.objfqy.SendDeviceCmd(24);//
        }

        public static double DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            double dateDiff = 0;
            TimeSpan ts = DateTime1.Subtract(DateTime2).Duration();
            dateDiff = ts.Days * 60 * 60 * 60 * 1000 + ts.Hours * 60 * 60 * 1000 + ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
            return dateDiff;
        }

        private void skinButton12_Click(object sender, EventArgs e)
        {
            m_mainform.objfqy.SendDeviceCmd(24);
            timer1.Enabled = false;
        }

        DateTime dtimet90 = DateTime.Now;
        DateTime dtimet10 = DateTime.Now;
        bool bt90start = false;
        bool bt10start = false;
        private void skinButton13_Click(object sender, EventArgs e)
        {
            txtstartxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            m_mainform.objfqy.SendDeviceCmd(29);//
            dtimet90 = DateTime.Now;
            bt90start = true;
            timer1.Enabled = true;
            bxysjhc = true;
            bxysjco = true;
            bxysjno = true;
            bxysjco2 = true;
            this.Invoke(new Action(() => { this.txttishi.Text = "响应时间T90检定开始"; }));

        }

        private void skinButton14_Click(object sender, EventArgs e)
        {
            txtendxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            bt90start = false;
            m_mainform.objfqy.SendDeviceCmd(24);
            bxysjhc = false;
            bxysjco = false;
            bxysjno = false;
            bxysjco2 = false;
            this.Invoke(new Action(() => { this.txttishi.Text = "响应时间T90检定结束"; }));
        }

        private void skinButton16_Click(object sender, EventArgs e)
        {
            txtstartxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            m_mainform.objfqy.SendDeviceCmd(25);//
            dtimet10 = DateTime.Now;
            bt10start = true;
            timer1.Enabled = true;
            bxysjhc = true;
            bxysjco = true;
            bxysjno = true;
            bxysjco2 = true;
            this.Invoke(new Action(() => { this.txttishi.Text = "响应时间T10检定开始"; }));
        }

        private void skinButton15_Click(object sender, EventArgs e)
        {
            txtendxl.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            m_mainform.objfqy.SendDeviceCmd(24);
            bt10start = false;
            bxysjhc = false;
            bxysjco = false;
            bxysjno = false;
            bxysjco2 = false;
            this.Invoke(new Action(() => { this.txttishi.Text = "响应时间T10检定结束"; }));
        }
        bool bxysjhc = true;
        bool bxysjco = true;
        bool bxysjno = true;
        bool bxysjco2 = true;
        public void gett90()
        {
            float ft90xzhc = 0, ft90xzco = 0, ft90xzno = 0, ft90xzco2 = 0;
            float.TryParse(txtxysjt90xzhc.Text, out ft90xzhc);
            float.TryParse(txtxysjt90xzco.Text, out ft90xzco);
            float.TryParse(txtxysjt90xzno.Text, out ft90xzno);
            float.TryParse(txtxysjt90xzco2.Text, out ft90xzco2);

            float fxzhc = 0, fxzco = 0, fxzno = 0, fxzco2 = 0;
            float.TryParse(HC_bzz.Text, out fxzhc);
            float.TryParse(CO_bzz.Text, out fxzco);
            float.TryParse(NO_bzz.Text, out fxzno);
            float.TryParse(CO2_bzz.Text, out fxzco2);

            double dxysj = Math.Round(DateDiff(DateTime.Now, dtimet90) * 0.001, 1);
            if (bxysjhc && fxzhc * 0.9f <= m_mainform.objfqy.m_iHc) { bxysjhc = false; txtxysjt90hc.Text = dxysj.ToString("0.0"); txtxysjt90pdhc.Text = dxysj > ft90xzhc ? "不合格" : "合格"; }
            if (bxysjco && fxzco * 0.9f <= m_mainform.objfqy.m_fCo) { bxysjco = false; txtxysjt90co.Text = dxysj.ToString("0.0"); txtxysjt90pdco.Text = dxysj > ft90xzco ? "不合格" : "合格"; }
            if (bxysjno && fxzno * 0.9f <= m_mainform.objfqy.m_iNo) { bxysjno = false; txtxysjt90no.Text = dxysj.ToString("0.0"); txtxysjt90pdno.Text = dxysj > ft90xzno ? "不合格" : "合格"; }
            if (bxysjco2 && fxzco2 * 0.9f <= m_mainform.objfqy.m_fCo2) { bxysjco2 = false; txtxysjt90co2.Text = dxysj.ToString("0.0"); txtxysjt90pdco2.Text = dxysj > ft90xzco2 ? "不合格" : "合格"; }
        }

        public void gett10()
        {
            float ft10xzhc = 0, ft10xzco = 0, ft10xzno = 0, ft10xzco2 = 0;
            float.TryParse(txtxysjt10xzhc.Text, out ft10xzhc);
            float.TryParse(txtxysjt10xzco.Text, out ft10xzco);
            float.TryParse(txtxysjt10xzno.Text, out ft10xzno);
            float.TryParse(txtxysjt10xzco2.Text, out ft10xzco2);

            float fxzhc = 0, fxzco = 0, fxzno = 0, fxzco2 = 0;
            float.TryParse(HC_bzz.Text, out fxzhc);
            float.TryParse(CO_bzz.Text, out fxzco);
            float.TryParse(NO_bzz.Text, out fxzno);
            float.TryParse(CO2_bzz.Text, out fxzco2);

            double dxysj = Math.Round(DateDiff(DateTime.Now, dtimet10) * 0.001, 1);
            if (bxysjhc && fxzhc * 0.1f >= m_mainform.objfqy.m_iHc) { bxysjhc = false; txtxysjt10hc.Text = dxysj.ToString("0.0"); txtxysjt10pdhc.Text = dxysj > ft10xzhc ? "不合格" : "合格"; }
            if (bxysjco && fxzco * 0.1f >= m_mainform.objfqy.m_fCo) { bxysjco = false; txtxysjt10co.Text = dxysj.ToString("0.0"); txtxysjt10pdco.Text = dxysj > ft10xzco ? "不合格" : "合格"; }
            if (bxysjno && fxzno * 0.1f >= m_mainform.objfqy.m_iNo) { bxysjno = false; txtxysjt10no.Text = dxysj.ToString("0.0"); txtxysjt10pdno.Text = dxysj > ft10xzno ? "不合格" : "合格"; }
            if (bxysjco2 && fxzco2 * 0.1f >= m_mainform.objfqy.m_fCo2) { bxysjco2 = false; txtxysjt10co2.Text = dxysj.ToString("0.0"); txtxysjt10pdco2.Text = dxysj > ft10xzco2 ? "不合格" : "合格"; }
        }
        public void getldpy()
        {
            text_dpjg.Text = "测量中";
            if (HC_cyz.Text.Length < 1) HC_cyz.Text = "0";
            if (CO_cyz.Text.Length < 1) CO_cyz.Text = "0";
            if (NO_cyz.Text.Length < 1) NO_cyz.Text = "0";
            if (CO2_cyz.Text.Length < 1) CO2_cyz.Text = "0";
            if (O2_cyz.Text.Length < 1) O2_cyz.Text = "0";
            HC_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_iHc > float.Parse(HC_cyz.Text) ? m_mainform.objfqy.m_iHc : float.Parse(HC_cyz.Text));
            CO_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_fCo > float.Parse(CO_cyz.Text) ? m_mainform.objfqy.m_fCo : float.Parse(CO_cyz.Text));
            NO_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_iNo > float.Parse(NO_cyz.Text) ? m_mainform.objfqy.m_iNo : float.Parse(NO_cyz.Text));
            CO2_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_fCo2 > float.Parse(CO2_cyz.Text) ? m_mainform.objfqy.m_fCo2 : float.Parse(CO2_cyz.Text));
            O2_cyz.Text = string.Format(@"{0}", m_mainform.objfqy.m_fO2 > float.Parse(O2_cyz.Text) ? m_mainform.objfqy.m_fO2 : float.Parse(O2_cyz.Text));
            if (m_mainform.DateDiff(DateTime.Now, dtimetldpy) > 1000 * 600)
            {
                text_dpjg.Text = "合格";
                if (Math.Abs(float.Parse(txthcjdc.Text)) > 4)
                {
                    text_dpjg.Text = "不合格";
                }
                if (Math.Abs(float.Parse(txtcojdc.Text)) > 0.02)
                {
                    text_dpjg.Text = "不合格";
                }
                if (Math.Abs(float.Parse(txtnojdc.Text)) > 0.3)
                {
                    text_dpjg.Text = "不合格";
                }
                if (Math.Abs(float.Parse(txtco2jdc.Text)) > 25)
                {
                    text_dpjg.Text = "不合格";
                }
                if (Math.Abs(float.Parse(txto2jdc.Text)) > 0.1 || float.Parse(txto2xdc.Text)>5)
                {
                    text_dpjg.Text = "不合格";
                }
                bldpy = false;
                timer1.Enabled = false;
                this.Invoke(new Action(() => { this.txttishi.Text = "零点飘移检定结束"; }));
            }
        }
        public void shuaxin()
        {
            double dbzz = 0, dcyz = 0, djdc = 0, dxdc = 0;
            double.TryParse(HC_bzz.Text, out dbzz);
            double.TryParse(HC_cyz.Text, out dcyz);
            djdc = Math.Abs(dbzz - dcyz);
            dxdc = Math.Round(100*Math.Abs(dbzz - dcyz) / dbzz, 2);
            txthcjdc.Text = djdc.ToString("0.00");
            if (bldpy) { txthcxdc.Text = "-"; } else { txthcxdc.Text = dxdc.ToString(); }           
            
            //---------------------------------------
            double.TryParse(CO_bzz.Text, out dbzz);
            double.TryParse(CO_cyz.Text, out dcyz);
            djdc = Math.Abs(dbzz - dcyz);
            dxdc = Math.Round(100 * Math.Abs(dbzz - dcyz) / dbzz, 2);
            txtcojdc.Text = djdc.ToString("0.00");
            if (bldpy) { txtcoxdc.Text = "-"; } else { txtcoxdc.Text = dxdc.ToString(); }


            double.TryParse(NO_bzz.Text, out dbzz);
            double.TryParse(NO_cyz.Text, out dcyz);
            djdc = Math.Abs(dbzz - dcyz);
            dxdc = Math.Round(100 * Math.Abs(dbzz - dcyz) / dbzz, 2);
            txtnojdc.Text = djdc.ToString("0.00");
            if (bldpy) { txtnoxdc.Text = "-"; } else { txtnoxdc.Text = dxdc.ToString(); }

            double.TryParse(CO2_bzz.Text, out dbzz);
            double.TryParse(CO2_cyz.Text, out dcyz);
            djdc = Math.Abs(dbzz - dcyz);
            dxdc = Math.Round(100 * Math.Abs(dbzz - dcyz) / dbzz, 2);
            txtco2jdc.Text = djdc.ToString("0.00");
            if (bldpy) { txtco2xdc.Text = "-"; } else { txtco2xdc.Text = dxdc.ToString(); }

            double.TryParse(O2_bzz.Text, out dbzz);
            double.TryParse(O2_cyz.Text, out dcyz);
            djdc = Math.Abs(dbzz - dcyz);
            dxdc = Math.Round(100 * Math.Abs(dbzz - dcyz) / dbzz, 2);
            txto2jdc.Text = djdc.ToString("0.00");
            txto2xdc.Text = dxdc.ToString();

            if (!bldpy && !bt10start && !bt90start)
            {
                if (float.Parse(CO_bzz.Text) < 10) text_hgco.Text = string.Format("±3%/±0.02");
                if (float.Parse(CO_bzz.Text) > 10.01 && float.Parse(CO_bzz.Text) < 14.00) text_hgco.Text = string.Format("±5%/-");
                if (float.Parse(HC_bzz.Text) < 2000) text_hghc.Text = string.Format("±3%/±4");
                if (float.Parse(HC_bzz.Text) > 2001 && float.Parse(HC_bzz.Text) < 5000) text_hghc.Text = string.Format("±5/-");
                if (float.Parse(HC_bzz.Text) > 5001 && float.Parse(HC_bzz.Text) < 9999) text_hghc.Text = string.Format("±10/-");
                if (float.Parse(NO_bzz.Text) < 4000) text_hgno.Text = string.Format("±4%/25");
                if (float.Parse(NO_bzz.Text) > 4001 && float.Parse(NO_bzz.Text) < 5000) text_hgno.Text = string.Format("±8%/-");
                if (float.Parse(CO2_bzz.Text) < 16) text_hgco2.Text = string.Format("±3%/±0.02");
                if (float.Parse(CO2_bzz.Text) > 16.01 && float.Parse(CO2_bzz.Text) < 18.00) text_hgco2.Text = string.Format("±5%/-");
                text_hgo2.Text = "-";
            }
        }
        private void skinButton2_Click_1(object sender, EventArgs e)
        {
            bt10start = false;
            bt90start = false;
            bldpy = false;
            bssxysj = false;
            bxjxysj = false;
            timer1.Enabled = false;
            m_mainform.objfqy.SendDeviceCmd(24);

        }


        private void ylc_cyz_TextChanged(object sender, EventArgs e)
        {
            textBox5.Text = "";
            double f1 = 0, f2 = 0, f3 = 0;
            if (ylc_bzz.Text.Length < 1)
            {
                MessageBox.Show("请输入标准值");
                return;
            }
            else
            {
                double.TryParse(ylc_cyz.Text, out f1);
                double.TryParse(ylc_bzz.Text, out f2);
                double.TryParse(ylc_jdc.Text, out f3);
                f3 = Math.Round((Math.Abs(f1 - f2))*100)/100;
                ylc_jdc.Text = f3.ToString("0.00");
                if (f3 > 0.1)
                    textBox5.Text = "不合格";
                else
                    textBox5.Text = "合格";

            }
            

        }

        private void HC_cyz_TextChanged(object sender, EventArgs e)
        {
            if (!timer1.Enabled)
            {
                if (HC_cyz.Text.Length > 0 && CO_cyz.Text.Length > 0 && NO_cyz.Text.Length > 0 && CO2_cyz.Text.Length > 0 && O2_cyz.Text.Length > 0)
                    shuaxin();
            }
        }

        private void txtxysjt90hc_TextChanged(object sender, EventArgs e)
        {
            if (!timer1.Enabled)
            {
                if (txtxysjt90hc.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt90hc.Text) > float.Parse(txtxysjt90xzhc.Text))

                        txtxysjt90pdhc.Text = "不合格";
                    else
                        txtxysjt90pdhc.Text = "合格"; 
                }
                if (txtxysjt90co.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt90co.Text) > float.Parse(txtxysjt90xzco.Text))

                        txtxysjt90pdco.Text = "不合格";
                    else
                        txtxysjt90pdco.Text = "合格";
                }
                if (txtxysjt90no.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt90no.Text) > float.Parse(txtxysjt90xzno.Text))

                        txtxysjt90pdno.Text = "不合格";
                    else
                        txtxysjt90pdno.Text = "合格";
                }
                if (txtxysjt90co2.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt90co2.Text) > float.Parse(txtxysjt90xzco2.Text))

                        txtxysjt90pdco2.Text = "不合格";
                    else
                        txtxysjt90pdco2.Text = "合格";
                }
            }
        }

        private void txtxysjt10hc_TextChanged(object sender, EventArgs e)
        {
            if (!timer1.Enabled)
            {
                if (txtxysjt10hc.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt10hc.Text) > float.Parse(txtxysjt10xzhc.Text))

                        txtxysjt10pdhc.Text = "不合格";
                    else
                        txtxysjt10pdhc.Text = "合格";
                }
                if (txtxysjt10co.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt10co.Text) > float.Parse(txtxysjt10xzco.Text))

                        txtxysjt10pdco.Text = "不合格";
                    else
                        txtxysjt10pdco.Text = "合格";
                }
                if (txtxysjt10no.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt10no.Text) > float.Parse(txtxysjt10xzno.Text))

                        txtxysjt10pdno.Text = "不合格";
                    else
                        txtxysjt10pdno.Text = "合格";
                }
                if (txtxysjt10co2.Text.Length > 0)
                {
                    if (float.Parse(txtxysjt10co2.Text) > float.Parse(txtxysjt10xzco2.Text))

                        txtxysjt10pdco2.Text = "不合格";
                    else
                        txtxysjt10pdco2.Text = "合格";
                }
            }
        }

        private void skinButton11_Click_1(object sender, EventArgs e)
        {
            if (CBBND.Text.Contains("1-低浓度"))
            {
                联网通信协议.云景model.HJ24 objcybd = new 联网通信协议.云景model.HJ24();
                objcybd.StationCode = m_mainform.StationCode;
                objcybd.SceneCode = m_mainform.lineCode;
                objcybd.GasType = "2";
                objcybd.HCEL = HC_bzz.Text;
                objcybd.HCER = HC_cyz.Text;
                objcybd.HCED = "1";
                objcybd.COEL = CO_bzz.Text;
                objcybd.COER = CO_cyz.Text;
                objcybd.COED = "1";
                objcybd.NOEL = NO_bzz.Text;
                objcybd.NOER = NO_cyz.Text;
                objcybd.NOED = "1";
                objcybd.CO2EL = CO2_bzz.Text;
                objcybd.CO2ER = CO2_cyz.Text;
                objcybd.CO2ED = "1";
                objcybd.O2EL = O2_bzz.Text;
                objcybd.O2ER = O2_cyz.Text;
                objcybd.O2ED = "1";
                objcybd.PEF = txtpef.Text;
                objcybd.C3H8 = C3H8_BZZ.Text;
                objcybd.AdjustResult = "1";
                objcybd.AdjustTimeStart = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                objcybd.AdjustTimeEnd = DateTime.Now.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss");

                string sjieguo = string.Format(@"汽油线标定信息：{0}", JsonConvert.SerializeObject(objcybd));
                string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                             "汽油线标定信息",
                                             sjieguo,
                                             DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                             m_mainform.lineCode);
                m_mainform.objbassLW.objdb.InsertDB(ssqlex);
                MessageBox.Show(m_mainform.objbass.uploadzj(objcybd));
            }
            else
            {
                MessageBox.Show("低标气体才需上传！");
            }
        }

        private void skinButton18_Click(object sender, EventArgs e)
        {

            threadzj = new Thread(zijian);
            threadzj.Start();
        }
        public Thread threadzj;
        public bool bzijian = true;
        public void zijian()
        {
            m_mainform.objfqy.SendDeviceCmd(26);//
            sxianshineirong = string.Format(@"正在检测环境空气");
            xianshixinxizt();
            Thread.Sleep(2000);
            DateTime dtime = DateTime.Now;
            while (true)
            {
                if (!bzijian)
                {
                    m_mainform.objfqy.SendDeviceCmd(24);//
                    return;
                }
                m_mainform.objfqy.SendDeviceCmd(3);//
                Thread.Sleep(300);
                sxianshineirong = string.Format(@"HC:{0}。CO:{1}。NO:{2}。", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                xianshixinxizt();
                //Thread.Sleep(2000);
                if (dtime.AddSeconds(15) < DateTime.Now)
                {
                    sendzijian("1", "3", dtime, DateTime.Now);
                    sendzijian("1", "2", dtime, DateTime.Now);
                    break;
                }
            }
            Thread.Sleep(1000);
            m_mainform.objfqy.SendDeviceCmd(24);//
            sxianshineirong = string.Format(@"环境空气检测完成");
            xianshixinxizt();
            Thread.Sleep(2000);
            sxianshineirong = string.Format(@"正在检测背景空气");
            xianshixinxizt();
            Thread.Sleep(1000);
            m_mainform.objfqy.SendDeviceCmd(25);//dtime = DateTime.Now;
            dtime = DateTime.Now;
            while (true)
            {
                if (!bzijian)
                {
                    m_mainform.objfqy.SendDeviceCmd(24);//
                    return;
                }
                m_mainform.objfqy.SendDeviceCmd(3);//
                Thread.Sleep(300);
                sxianshineirong = string.Format(@"HC:{0}。CO:{1}。NO:{2}。", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                xianshixinxizt();
                bool bpd = true;
                if (m_mainform.objfqy.m_iHc > 7 || m_mainform.objfqy.m_fCo >= 0.02 || m_mainform.objfqy.m_iNo >= 5)
                {
                    Thread.Sleep(2000);
                    sxianshineirong = string.Format(@"背景空气检测不合格");
                    xianshixinxizt();
                    bpd = false;
                    Thread.Sleep(2000);
                }
                if (bpd && dtime.AddSeconds(14) < DateTime.Now)
                {
                    sendzijian("1", "4", dtime, DateTime.Now);
                    sendzijian("1", "1", dtime, DateTime.Now);
                    break;
                }
            }
            //Thread.Sleep(1000);
            //m_mainform.objfqy.SendDeviceCmd(2);//
            Thread.Sleep(1000);
            m_mainform.objfqy.SendDeviceCmd(24);//
            sxianshineirong = string.Format(@"背景空气合格");
            xianshixinxizt();
            Thread.Sleep(2000);
            sxianshineirong = string.Format(@"已经上传成功");
            xianshixinxizt();

        }
        public void sendzijian(string sCheckJudge, string sCheckType, DateTime sCheckTimeStart, DateTime sCheckTimeEnd)
        {
            // CheckType:1-HC残留检查 2-零点校正 3-环境空气测定4-背景空气浓度取样
            联网通信协议.云景model.HJ42 objzj = new 联网通信协议.云景model.HJ42()
            {
                StationCode = m_mainform.stationCode,
                SceneCode = m_mainform.lineCode,
                CheckJudge = sCheckJudge,
                CheckType = sCheckType,
                CheckTimeStart = sCheckTimeStart.ToString("yyyy-MM-dd HH:mm:ss"),
                CheckTimeEnd = sCheckTimeEnd.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(objzj);
            string sjieguo = m_mainform.objbass.senddate("HJ42", svalue);
        }

        private void xianshixinxizt()
        {
            if (this.xl_fq.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxizt);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xianshizhuantai.Text = string.Format(@"{0}", sxianshineirong);
            }
        }

        private void skinButton17_Click(object sender, EventArgs e)
        {
            bzijian = false;
            sxianshineirong = string.Format(@"已经中止");
            xianshixinxizt();
        }
        public void keyixiugai(bool zt)
        {
            HC_cyz.Enabled = zt;
            CO_cyz.Enabled = zt;
            NO_cyz.Enabled = zt;
            CO2_cyz.Enabled = zt;
            O2_cyz.Enabled = zt;
            text_dpjg.Enabled = zt;
            xianshizhuantai.Enabled = zt;
            xl_fq.Enabled = zt;
        }

        private void yiqijianding_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                keyixiugai(true);
            }
        }

        private void yiqijianding_KeyUp(object sender, KeyEventArgs e)
        {
            //keyixiugai(false);
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }
        public void getqiti(string ranyou,string qiti)
        {
            string sql = string.Format("select * from qititable where ranyou='{0}' and qitileixing='{1}'", ranyou, qiti);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                C3H8_BZZ.Text = dt.Rows[0]["C3H8"].ToString().Trim().Length > 0 ? dt.Rows[0]["C3H8"].ToString().Trim() : "0";    //填充第二列的数
                CO_bzz.Text = dt.Rows[0]["CO"].ToString().Trim().Length > 0 ? dt.Rows[0]["CO"].ToString().Trim() : "0";    //填充第二列的数据 据 
                NO_bzz.Text = dt.Rows[0]["NO"].ToString().Trim().Length > 0 ? dt.Rows[0]["NO"].ToString().Trim() : "0";    //填充第二列的数据 
                CO2_bzz.Text = dt.Rows[0]["CO2"].ToString().Trim().Length > 0 ? dt.Rows[0]["CO2"].ToString().Trim() : "0";    //填充第二列的数据 
                O2_bzz.Text = dt.Rows[0]["O2"].ToString().Trim().Length > 0 ? dt.Rows[0]["O2"].ToString().Trim() : "0";    //填充第二列的数据 
            }
        }

        private void CBBND_SelectedIndexChanged(object sender, EventArgs e)
        {
            getqiti("汽油", CBBND.Text);
        }

        private void yiqijianding_Shown(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }
    }
}
